package com.hsjk.szwj.module.train.controller.admin;

import com.hsjk.szwj.framework.common.pojo.CommonResult;
import com.hsjk.szwj.framework.common.pojo.PageResult;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseLiveCreateReqVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseLiveDetailRespVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseLivePageReqVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseLivePageRespVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseLivePageSearchRespVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseLiveSearchPageReqVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseLiveUpdateReqVO;
import com.hsjk.szwj.module.train.service.ICourseLiveService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.hsjk.szwj.framework.common.pojo.CommonResult.success;

/**
 * @author chenjiawei
 * @desc
 * @Date 2023/10/28 16:04
 **/
@Tag(name = "后台管理端 - 课程直播相关接口")
@RestController
@RequestMapping("/train/course/live")
@Validated
public class AdminCourseLiveController {
    @Resource
    private ICourseLiveService courseLiveService;

    @PostMapping("/page-course-live")
    @Operation(summary = "分页获取课程直播列表")
    @PreAuthorize("@ss.hasPermission('train:course-live:query')")
    public CommonResult<PageResult<AdminCourseLivePageRespVO>> getCourseLivePage(@RequestBody @Valid AdminCourseLivePageReqVO reqVO) {
        return success(courseLiveService.getCourseLivePage(reqVO));
    }

    @PostMapping("/page-course-live-search")
    @Operation(summary = "课程直播分页查询")
    @PreAuthorize("@ss.hasPermission('train:course-live:query')")
    public CommonResult<PageResult<AdminCourseLivePageSearchRespVO>> getCourseLiveSearchPage(@RequestBody @Valid AdminCourseLiveSearchPageReqVO reqVO) {
        return success(courseLiveService.getCourseLiveSearchPage(reqVO));
    }

    @GetMapping("/get-course-live-detail")
    @Operation(summary = "获取课程直播详情")
    @PreAuthorize("@ss.hasPermission('train:course-live:query')")
    public CommonResult<AdminCourseLiveDetailRespVO> getCourseLiveDetail(@RequestParam Long id) {
        return success(courseLiveService.getCourseLiveDetail(id));
    }

    @PostMapping("/create")
    @Operation(summary = "新增课程直播")
    @PreAuthorize("@ss.hasPermission('train:course-live:create')")
    public CommonResult<Boolean> createCourseLive(@RequestBody @Valid AdminCourseLiveCreateReqVO reqVO) {
        return success(courseLiveService.createCourseLive(reqVO));
    }

    @PostMapping("/update")
    @Operation(summary = "更新课程直播")
    @PreAuthorize("@ss.hasPermission('train:course-live:update')")
    public CommonResult<Boolean> updateCourseLive(@RequestBody @Valid AdminCourseLiveUpdateReqVO reqVO) {
        return success(courseLiveService.updateCourseLive(reqVO));
    }

    @PostMapping("/delete")
    @Operation(summary = "删除课程直播")
    @PreAuthorize("@ss.hasPermission('train:course-live:delete')")
    public CommonResult<Boolean> deleteCourseLive(@RequestParam Long id) {
        return success(courseLiveService.deleteCourseLive(id));
    }
}
